package com.functest.jpwise

import com.functest.jpwise.algo.CombinatorialAlgorithm
import com.functest.jpwise.algo.PairwiseAlgorithm
import com.functest.jpwise.core.CombinationTable
import com.functest.jpwise.core.TestGenerator
import com.functest.jpwise.core.SimpleValue
import com.functest.jpwise.core.TestInput
import com.functest.jpwise.core.TestParameter
import com.functest.framework.BaseFunctionalTest
import com.functest.orm.ConditionOp
import org.testng.annotations.Test

/**
 * @author: DavydovMD
 * Date: 17.06.13
 * Time: 18:19
 */
class BasicJpWiseTest extends BaseFunctionalTest {

    @Test
    void testPairs() {
        TestInput input = new TestInput()
        input.add(new TestParameter('parameterA', [SimpleValue.of(3), SimpleValue.of(5)]))
        input.add(new TestParameter('parameterB', [SimpleValue.of('a')]))
        input.add(new TestParameter('parameterC', [SimpleValue.of(5L), SimpleValue.of(8L), SimpleValue.of(42L), SimpleValue.of(Math.PI)]))
        input.add(new SmartParameter(
                'parameterD',
                [SimpleValue.of(4L), SimpleValue.of(9L), SimpleValue.of(43L), SimpleValue.of(Math.E)],
                [
                        CompatibleIf.thisIs(new ConditionBasedMatcher(ConditionBasedMatcher.Field.Value, ConditionOp.EQ, 4L))
                        , CompatibleIf.thatIs(new ConditionBasedMatcher(ConditionBasedMatcher.Field.ParameterName, ConditionOp.NEQ, 'parameterA'))
                        , CompatibleIf.thatIs(
                        new ConditionBasedMatcher(ConditionBasedMatcher.Field.ParameterName, ConditionOp.EQ,
                                'parameterA', ConditionBasedMatcher.Field.Name, ConditionOp.EQ, '3') )

                ]
        ))

        TestGenerator generator = new TestGenerator(input)
        generator.generate(new PairwiseAlgorithm(5), 2)
        CombinationTable table = generator.result()
        table.combinations()
        table.combinations().each {
            logger.info("$it")
        }
        assert table.combinations().size()==17

    }

    @Test
    void testCombi() {
        TestInput input = new TestInput()
        input.add(new TestParameter('parameterA', [SimpleValue.of(3), SimpleValue.of(5)]))
        input.add(new TestParameter('parameterB', [SimpleValue.of('a')]))
        input.add(new TestParameter('parameterC', [SimpleValue.of(5L), SimpleValue.of(8L), SimpleValue.of(42L), SimpleValue.of(Math.PI)]))
        input.add(new SmartParameter(
                'parameterD',
                [SimpleValue.of(4L), SimpleValue.of(9L), SimpleValue.of(43L), SimpleValue.of(Math.E)],
                [
                        CompatibleIf.thisIs(new ConditionBasedMatcher(ConditionBasedMatcher.Field.Value, ConditionOp.EQ, 4L))
                        , CompatibleIf.thatIs(new ConditionBasedMatcher(ConditionBasedMatcher.Field.ParameterName, ConditionOp.NEQ, 'parameterA'))
                        , CompatibleIf.thatIs(
                        new ConditionBasedMatcher(ConditionBasedMatcher.Field.ParameterName, ConditionOp.EQ,
                                'parameterA', ConditionBasedMatcher.Field.Name, ConditionOp.EQ, '3') )

                ]
        ))

        TestGenerator generator = new TestGenerator(input)
        generator.generate(new CombinatorialAlgorithm(), 99)
        CombinationTable table = generator.result()
        table.combinations()
        table.combinations().each {
            logger.info("$it")
        }
        assert table.combinations().size()==20

    }




}
